package com.yj.ccs.abs.boot.config.mybatis.handler;

import com.yj.ccs.abs.common.enums.ContractType;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Copyright 2018 (C) Yunjian-VC
 * Created on : 2018/3/20
 * Author     : Unbelievable9
 **/
public class ContractTypeHandler extends BaseTypeHandler<ContractType> {
    @Override
    public void setNonNullParameter(PreparedStatement preparedStatement, int i, ContractType contractType, JdbcType jdbcType) throws SQLException {
        preparedStatement.setInt(i, contractType.getValue());
    }

    @Override
    public ContractType getNullableResult(ResultSet resultSet, String s) throws SQLException {
        return ContractType.fromValue(resultSet.getInt(s));
    }

    @Override
    public ContractType getNullableResult(ResultSet resultSet, int i) throws SQLException {
        return ContractType.fromValue(resultSet.getInt(i));
    }

    @Override
    public ContractType getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
        return ContractType.fromValue(callableStatement.getInt(i));
    }
}
